import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:interview/components/app/app_ripple_button.dart';
import 'package:interview/components/tag.dart';
import 'package:interview/controller/navigation_controller.dart';
import 'package:interview/theme/app_colors.dart';

class InterviewItem extends StatelessWidget {
  final AppColors theme;
  final String tab;
  final String id;
  final List<String> ids;
  final String stem;
  final String content;
  final String subjectName;
  final String creatorName;
  final String createdAt;
  final String creatorAvatar;
  final int difficulty;
  final int questionType;
  final int likeCount;
  final int likeFlag;
  final int views;

  InterviewItem({
    super.key, 
    required this.tab,
    required this.ids,
    required this.id,
    required this.theme, 
    required this.stem, 
    required this.content, 
    required this.subjectName, 
    required this.creatorName, 
    required this.createdAt, 
    required this.creatorAvatar, 
    required this.difficulty, 
    required this.questionType, 
    required this.likeCount, 
    required this.likeFlag,
    required this.views
  });

  final navigation = Get.find<NavigationController>();



  void onTap (){
    navigation.pushWithAuth(
      '/questionpage' , 
      parameters: {
        "id":id , 
        "ids":ids , 
        "typeId":0,
        "views":views,
        "tab":tab
      }
    );
  }

  @override
  Widget build(BuildContext context) {
    return AppRippleButton(
      rippleRadius:BorderRadius.circular(8),
      borderRadius:BorderRadius.circular(8),
      backgroundColor: theme.subjectPure!,
      splashColor:theme.contrastMix3!.withOpacity(0.2),
      highlightColor:theme.subjectMix1!.withOpacity(0.1),
      onTap: onTap,
      child:Container(
        width: double.infinity,
        padding: EdgeInsets.symmetric(horizontal: 16 , vertical: 12),
        child: Column(
          children: [
            Row(
              children: [
                CircleAvatar(
                  backgroundImage: NetworkImage(creatorAvatar),
                  radius: 16,
                ),
                SizedBox(width: 12,),
                Expanded(child: 
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("$stem", overflow: TextOverflow.ellipsis, maxLines: 1, style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold, color: theme.contrastPure),),
                      Row(
                        children: [
                          Text(creatorName , style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500, color: theme.contrastMix1)),
                          SizedBox(width: 6),
                          Text(createdAt , style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500, color: theme.contrastMix1))
                        ],
                      )
                    ],
                  )
                )
              ],
            ),
            Padding(padding: EdgeInsets.symmetric(vertical: 12), child:
              Text(content , maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: theme.contrastMix3))
            ),
            Row(
              children: [
                Tag(difficulty: difficulty,),
                SizedBox(width: 4),
                Tag(text: subjectName,)
              ],
            ),
            const SizedBox(height: 8), // 间距
            Row(
              crossAxisAlignment: CrossAxisAlignment.center, // 确保内容垂直居中对齐
              children: [
                _buildText("点赞 ${likeCount}"),
                _buildText("浏览 ${views}"),
              ],
            ),
          ],
        ),
      )
    );
  }

  Widget _buildText(String text) {
    return Padding(
      padding: const EdgeInsets.only(right: 8), // 添加每个文本间距
      child: Text(
        text,
        style: const TextStyle(fontSize: 10, color: Colors.grey),
      ),
    );
  }
}